#define  _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
typedef struct ListNode ListNode;
struct ListNode* removeElements(struct ListNode* head, int val)
{
    if (head == NULL)
    {
        return head;
    }
    ListNode* newhead, * newpcur;
    newhead = newpcur = NULL;
    ListNode* pcur = head;
    while (pcur)
    {
        if (pcur->val != val)
        {
            if (newhead == NULL)
            {
                newhead = newpcur = pcur;
            }
            else
            {
                newpcur->next = pcur;
                newpcur = newpcur->next;

            }
        }
        pcur = pcur->next;
    }
    if (newhead)
        newpcur->next = NULL;

    return newhead;




}